<?php

	if (!defined('EXPONENT')) exit('');

	if (exponent_users_isAdmin() || exponent_permissions_check(array("administrate"),$loc))
	{

		$fuser = null;
		if (isset($_REQUEST['id'])) {
			$fuser = $db->selectObject('filemanagermodule_users','id='.$_REQUEST['id']);
		}
		
		
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();
		
		$form = new form();
		if (!isset($fuser->id)) {
			$fuser->homedir="/files/";
			$fuser->show_hidden = 0;
			$fuser->pattern_hidden="";
			$fuser->permissions = 0;
			$fuser->active = 1;
			$fuser->user_id =0;
		} else {
			$form->meta('id',$fuser->id);
		}
		
		if ($fuser->user_id > 0)
		{
			// edit
			$form->meta('user_id',$fuser->user_id);
		}
		else
		{
			$users=$db->selectDropdown('user','username');
			$form->register('user_id','Select user',new dropdowncontrol($fuser->user_id,$users,false));
		}
		
		$form->register('homedir','Home directory',new textcontrol($fuser->homedir));
		$yes_no=array();
		$yes_no[0]="No";
		$yes_no[1]="Yes";
		$form->register('show_hidden','Show hidden',new dropdowncontrol($fuser->show_hidden,$yes_no,false));
		
		$form->register('pattern_hidden','Pattern hidden',new textcontrol($fuser->pattern_hidden));
		
		$permissions=array();
		$permissions[0]="View only";
		$permissions[1]="Modify";
		$permissions[2]="Change password";
		$permissions[3]="Modify & Change password";
		$permissions[7]="Administrator";
		
		$form->register('permissions','Permissions',new dropdowncontrol($fuser->permissions,$permissions,false));
		
		$form->register('active','Active',new dropdowncontrol($fuser->active,$yes_no,false));
		$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
		
		
		$form->location($loc);
		$form->meta('action','manager_user_save');

		$template = new template('filemanagermodule','_form_manage_user_edit');
		$template->assign('is_edit',(isset($user->id)? 0 : 1));
		$template->assign('form_html',$form->toHTML());
		$template->output();
	} else {
		echo exponent_http_error(403);
	}

?>
